<template>
  <div class="wapper">
    <el-container style="100%">
      <ProjectDoorType></ProjectDoorType>
      <el-main style="background:#fff;margin-left:10px">
        <div class="table-wrap" v-show="listShow">
          <div class="handle-box3">
            <el-form :inline="true" ref="form" class="demo-form-inline">
              <div class="uers-left">
                <el-form-item label="票类型：">
                  <el-select v-model="ticketTypeId" placeholder="选择票类型">
                    <el-option
                      v-for="(type,index) in TicketType"
                      :label="type.name"
                      :key="index"
                      :value="type.ticketTypeId">
                      <div @click="getChangeTicketType(type)">{{type.name}}</div>
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="证件类型：">
                  <el-select v-model="documentTypeId" placeholder="选择证件类型">
                    <el-option
                      v-for="(type,index) in DocumentType"
                      :label="type.name"
                      :key="index"
                      :value="type.documentTypeId">
                      <div @click="getChangeDocuType(type)">{{type.name}}</div>
                    </el-option>
                  </el-select>
                </el-form-item>
              </div>
              <div class="uers-right">
                <span class="btn-r">
                  <el-button type="primary" plain icon="el-icon-plus" @click="addSubmit">新增</el-button>
                </span>
              </div>
            </el-form>
          </div>
          <div class="tabbox">
          <el-table
            :data="dataList"
            height="100%"
            border
            class="tabbox"
            ref="multipleTable"
            :header-cell-style="{background:'#f2f6fc',color:'#606266'}"
            @selection-change="handleSelectionChange"
          >
            <el-table-column type="selection" width="55" align="center"></el-table-column>
            <el-table-column prop="faceMatch" label="人脸识别" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.faceMatch==0?'不人脸识别':(scope.row.faceMatch==1?'人证核验':(scope.row.faceMatch==2?' 人脸识别':'人证核验或人脸识别'))}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="faceCollect" label="人脸采集" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.faceCollect==0?'不采集':(scope.row.faceCollect==1?'采集人脸后开门':'采集现场照片')}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="name" label="类型名称" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.name}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="days" label="日期" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.days}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="frequency" label="次数" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.frequency}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="createDate" label="创建时间" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.createDate}}</span>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="180" align="center">
              <template slot-scope="scope">
                <el-button type="text" @click="handleEdit(scope.$index,scope.row)">编辑</el-button>
                <el-button type="text" class="red" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table></div>
          <div class="fb"><el-pagination
            class="pag"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[5, 10, 15, 20]"
            :page-size="pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            background
          ></el-pagination></div>
        </div>
        <DeleteDialog
          :delVisible="delVisible"
          @deleteData="deleteData"
          @handleCloseVisible="handleCloseVisible"
        ></DeleteDialog>
        <EditAccessManage :editShow="editShow" :editData="editData" @backFunStu="getFunStu"></EditAccessManage>
      </el-main>
    </el-container>
  </div>
</template>
<script>
import EditAccessManage from "../../../components/ticketing/data/EditAccessManage";
import ProjectDoorType from "../../../components/ticketing/data/doorType/ProjectDoorType";
import DeleteDialog from "../../../components/public/DeleteConfim";

export default {
  data() {
    return {
      total: 0, //总条数
      currentPage: 1, //初始页
      pagesize: 10, // 每页的数据
      editData: {},
      listShow: true,
      delVisible: false,
      accessRule_Id: "",
      editShow: false,
      dataList: [],
      multipleSelection: [],
      productId:localStorage.getItem('project_Id'),
      ticketTypeId:'票类型',
      documentTypeId:'证件类型',
      TicketType:[],
      DocumentType:[],
    };
  },
  mounted() {
    // this.tabheight=(this.$refs.getheight.offsetHeight-165)
  },
  created() {
    this.getData();
    this.getDocumentType();
    this.getTicketType();
  },
  methods: {
    handleSizeChange(val) {
      this.pagesize = val;
      this.getData();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getData();
    },
    handleEdit(index, row) {
      this.editData = row;
      this.listShow = false;
      this.editShow = true;
    },
    // 获取数据
    getData() {
      this.$axios.get('/AccessRule/Project/'+this.productId).then(res =>{
        if (res.data.hasError == false) {
          this.dataList = [...res.data.data]
          this.total = res.data.total;
        }
      })
    },
    addSubmit() {
      this.listShow = false;
      this.editShow = true;
    },
    handleDelete(index, row) {
      this.accessRule_Id = row.accessRuleId;
      this.delVisible = true;
    },
    deleteData() {
      this.$axios.delete(`/AccessRule/${this.accessRule_Id}`)
        .then(res =>{
            this.$message.success("删除成功！");
            this.delVisible = false
            this.getData();
        })
    },
    handleCloseVisible() {
      this.accessRule_Id = "";
      this.delVisible = false;
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    getFunStu() {
      this.listShow = true;
      this.editShow = false;
      this.getData();
    },
    getTicketType(){
      this.$axios.get('/TicketType/Project/'+this.productId).then(res =>{
        if (res.data.hasError == false) {
          this.TicketType = [...res.data.data]
        }
      })
    },
    getDocumentType(){
      this.$axios.get('/DocumentType/Project/'+this.productId).then(res =>{
        if (res.data.hasError == false) {
          this.DocumentType = [...res.data.data]
        }
      })
    },
    getChangeDocuType(type){
      this.$axios.get(`/AccessRule/DocumentType/${type.documentTypeId}`).then(res =>{
        if (res.data.hasError == false) {
          this.dataList = [...res.data.data]
          this.total = res.data.total;
        }
      })
    },
    getChangeTicketType(type){
      this.$axios.get(`/AccessRule/TicketType/${type.documentTypeId}`).then(res =>{
        if (res.data.hasError == false) {
          this.dataList = [...res.data.data]
          this.total = res.data.total;
        }
      })
    }
  },
  components: {
    EditAccessManage,
    ProjectDoorType,
    DeleteDialog
  }
};
</script>
<style lang="scss" scope>
.pag {
  position: absolute;
  bottom: 0;
}
.table-wrap {
  height: 100%;
  margin-left: 10px;
}
.el-main{
  border-radius: 5px;
  position: relative;
}
.uers-left {
  float: left;
}
.uers-right {
  float: right;
}
.el-dialog{
  height: auto;
}
</style>